/*
 *  Copyright 2015-2016, RenGu Technology (BeiJing) Co., Ltd.
 *  All right reserved.
 *
 *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED TO THIR PARTIES,
 *  COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 *  WITHOUT THE PRIOR WRITTEN PERMISSION OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  PackAcctDetail
 *
 *  Edit History:
 *      lizhangtao Created on 2020年05月13日
 *
 */
package cc.rengu.igas.acct.common.util;

import cc.rengu.igas.acct.common.constant.AcctCommonConstant;
import cc.rengu.igas.acct.common.dao.AcctSequenceMapper;
import cc.rengu.igas.acct.common.dao.impl.AcctSequenceMapperImpl;
import cc.rengu.igas.acct.common.entity.AcctDetail;
import cc.rengu.igas.acct.common.entity.AcctInfo;
import cc.rengu.igas.acct.common.enums.AcctCcyEnum;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.DateUtil;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.StringUtil;

/**
 * 组装账户登记明细
 *
 * @author lizhangtao
 * @version 1.0
 * @date 2020/5/8
 */
public class PackAcctDetail {

    public static AcctDetail packAcctDetail(String txnDate, String txnTime, String txnNum, String msgSrcId, String traceNo,
                                            String summary, String transAmt, AcctInfo acctInfo, String acctDate,
                                            String balance, String availableBalance, String freezeBalance,
                                            String debitCreditFlag, String origFrontSeqNum, String origAcctSeqNum, DbsUtil dbsUtil) {
        AcctDetail acctDetail = new AcctDetail();
        BeanUtil.beanCopy(acctInfo, acctDetail);
        String dateTimeMs = DateUtil.getCurrentDateTime(AcctCommonConstant.DATETIME_FORMAT_MS);
        acctDetail.setCreateTime(dateTimeMs);
        acctDetail.setUpdateTime(dateTimeMs);
        acctDetail.setAcctDate(acctDate);
        AcctSequenceMapper acctSequenceMapper = new AcctSequenceMapperImpl();
        String ssn = acctSequenceMapper.getNextAcctSeqNumSequenceNo(acctDetail, dbsUtil);
        acctDetail.setAcctSeqNum(ssn);
        //TODO 该版本不实现动态数据校验
        acctDetail.setAfterAcctDag(AcctCommonConstant.DEFAULT_DAG);
        acctDetail.setBeforeAcctDag(AcctCommonConstant.DEFAULT_DAG);
        acctDetail.setAfterAvailableBalance(availableBalance);
        acctDetail.setAfterBalance(balance);
        acctDetail.setAfterFreezeBalance(freezeBalance);
        acctDetail.setBeforeAvailableBalance(acctInfo.getAvailableBalance());
        acctDetail.setBeforeBalance(acctInfo.getAcctBalance());
        acctDetail.setBeforeFreezeBalance(acctInfo.getFreezeBalance());
        acctDetail.setDebitCreditFlag(debitCreditFlag);
        acctDetail.setFrontSeqNum(traceNo);
        if (!StringUtil.isEmptyOrNull(summary)) {
            acctDetail.setSummary(summary);
        }
        acctDetail.setTransAmt(transAmt);
        acctDetail.setTransCcy(AcctCcyEnum.RMB.getSrcCcy());
        acctDetail.setTxnDate(txnDate);
        acctDetail.setTxnTime(txnTime);
        acctDetail.setTxnNum(txnNum);
        acctDetail.setMsgSrcId(msgSrcId);
        acctDetail.setOrigAcctSeqNum(origAcctSeqNum);
        acctDetail.setOrigFrontSeqNum(origFrontSeqNum);
        return acctDetail;
    }

    public static AcctDetail packAcctDetail(String txnDate, String txnTime, String txnNum, String msgSrcId, String traceNo,
                                            String summary, String transAmt, AcctInfo acctInfo, String acctDate,
                                            String balance, String availableBalance, String freezeBalance,
                                            String debitCreditFlag, DbsUtil dbsUtil) {
        return PackAcctDetail.packAcctDetail(txnDate, txnTime, txnNum, msgSrcId, traceNo, summary, transAmt, acctInfo, acctDate,
                balance, availableBalance, freezeBalance, debitCreditFlag, null, null, dbsUtil);
    }

    public static AcctDetail packAcctDetail(String txnDate, String txnTime, String txnNum, String msgSrcId, String traceNo,
                                            String summary, String transAmt, AcctInfo acctInfo, String acctDate,
                                            String balance, String availableBalance, String freezeBalance,
                                            String debitCreditFlag, DbsUtil dbsUtil, int total) {
        AcctDetail acctDetail = PackAcctDetail.packAcctDetail(txnDate, txnTime, txnNum, msgSrcId, traceNo, summary, transAmt, acctInfo, acctDate,
                balance, availableBalance, freezeBalance, debitCreditFlag, dbsUtil);
        if (total > 0) {
            acctDetail.setRemark2(String.valueOf(total));
        }
        return acctDetail;
    }

    public static AcctDetail packAcctDetail(String txnDate, String txnTime, String txnNum, String msgSrcId, String traceNo,
                                            String summary, String transAmt, AcctInfo acctInfo, String acctDate,
                                            String balance, String availableBalance, String freezeBalance,
                                            String debitCreditFlag, String origFrontSeqNum, String origAcctSeqNum, DbsUtil dbsUtil, int total) {
        AcctDetail acctDetail = PackAcctDetail.packAcctDetail(txnDate, txnTime, txnNum, msgSrcId, traceNo, summary, transAmt, acctInfo, acctDate,
                balance, availableBalance, freezeBalance, debitCreditFlag, origFrontSeqNum, origAcctSeqNum, dbsUtil);
        if (total > 0) {
            acctDetail.setRemark2(String.valueOf(total));
        }
        return acctDetail;
    }
}
